<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page language="java" import="java.util.*" %>
<jsp:directive.page import="com.xr.common.CommUtil"/>
<jsp:directive.page import="com.bstek.dorado.data.db.*"/>
<jsp:directive.page import="com.bstek.dorado.utils.variant.VariantSet"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title></title>
<script language="javascript" src="<%=request.getContextPath()%>/dorado/smartweb2.loadUserLib.d?file=/lib/jquery1.8.2.min.js"></script>
 <script  src="<%=request.getContextPath()%>/dorado/smartweb2.loadUserLib.d?file=/lib/highcharts2.3.5.js"></script>
<script   src="<%=request.getContextPath()%>/dorado/smartweb2.loadUserLib.d?file=/lib/exporting2.3.5.js"></script>
<script type="text/javascript"> 
		 	<%
		 	DBStatement dbs=new DBStatement();
	    Map<String,String> hm=new HashMap();
		String x="",xMonth="",sql="";
		String sendMonthF="",sendMonthT="";  
		sendMonthF=request.getParameter("sendMonthF");
		sendMonthT=request.getParameter("sendMonthT");
		String strId=request.getParameter("strId");
		String hritemsId=request.getParameter("hritemsId");
		//String year=request.getParameter("year");
		dbs.setSql("select months_between(to_date('"+sendMonthT+"01','yyyyMMdd'),to_date('"+sendMonthF+"01','yyyyMMdd')) from dual ");
		if(dbs.query().getInt(0)>24){
		   dbs.setSql("select to_char(add_months(to_date('"+sendMonthT+"01','yyyyMMdd'),-24),'yyyyMM') from dual ");
		   sendMonthF=dbs.query().getString(0);
		}
		sql="select to_char(add_months(to_date('"+sendMonthF+"01','yyyyMMdd'),level-1),'yyyyMM') from dual connect by level<=(select months_between(to_date('"+sendMonthT+"01','yyyyMMdd'),to_date('"+sendMonthF+"01','yyyyMMdd')) from dual)+1";
		dbs.setSql(sql);
		List listM=dbs.queryForList();
		for(int i=0;i<listM.size();i++){
		  VariantSet vs=(VariantSet)listM.get(i);
		  xMonth+="'"+vs.getString(0).substring(2,6)+"',";
		  
		}
		xMonth=xMonth.substring(0,xMonth.length()-1); 
		String name="",data="",series="";
		
		sql="select company_id,company_name from org_company where company_id in("+strId+")";
		dbs.setSql(sql);
		List listCom=dbs.queryForList();
		if(listCom.size()==0){out.write("</script><body>没有数据被统计！<body>"); return;}
			for(int i=0;i<listCom.size();i++){
			  VariantSet vs=(VariantSet)listCom.get(i);
			  	sql="select distinct psn.company_id,ws.send_month,"
		        +"(SELECT sum(d.value) from wa_data d,wa_psn p,wa_send s where p.psn_id=d.psn_id and s.send_id=p.send_id and p.company_id=psn.company_id and s.send_month=ws.send_month and d.hritems_id in("+hritemsId+"))sumvalue "
		        +" from wa_psn psn, wa_send ws where ws.send_id = psn.send_id and psn.company_id ="+vs.getString("company_id")+" order by send_month";
		        dbs.setSql(sql);
		        List listData=dbs.queryForList();
		        for(int j=0;j<listData.size();j++){
			      VariantSet vsJ=(VariantSet)listData.get(j);
			      hm.put(vsJ.getString("send_month"),vsJ.getString("sumvalue"));
			    }
		        
			  	for(int j=0;j<listM.size();j++){
			      VariantSet vsJ=(VariantSet)listM.get(j);
			      data+=hm.get(vsJ.getString(0))+",";
			    }
			    series+="{name:'"+vs.getString("company_name")+"',data:["+data.substring(0,data.length()-1)+"]},";
			    data="";
			    hm.clear();
			}
		
	
		dbs.close();
			 
		series=series.substring(0,series.length()-1); 
			 
			 System.out.println(series);
		%>
		
		var chart;
			$(document).ready(function() {
				chart = new Highcharts.Chart({
					chart: {
						renderTo: 'container',
						defaultSeriesType: 'spline'
						//type:'spline'
					},
					title: {
						text: ''
					},
					subtitle: {
						text: ''
					},
					xAxis: {
						categories: [<%=xMonth%>]
					},
					yAxis: {
						title: {
							text: '金额(RMB)'
						}
					},
					tooltip: {
					    crosshairs: true,
						shared: true
					
					},
					plotOptions: {
						line: {
							dataLabels: {
								enabled: true
							},
							enableMouseTracking: false
						},
						spline: {
							marker: {
								radius: 4,
								lineColor: '#666666',
								lineWidth: 1
							}
						}
					},
					series: [<%=series%>]
				});
				
				
			});
				
		</script>

  </head>
  
  <body>
    <div id="container" style="width: 100%; height: 100%; margin: 0 auto"></div>

  </body>
</html>
